package Exc.domain;

import java.util.List;

/**
 * 范型 通用
 * @param <T> the type parameter
 * @author fengke
 */
public class PageResult<T> {
    //当前页
    private int currentPage;
    // 每页显示的条数
    private int pageSize;
    //查询数据总条数
    private int totalCount;
    //每页显示的结果集，使用范型的好处 通用性大大提高， 自己做项目的时候也要有这种思想
    private List<T> data;
    //计算的数据 总页面
    private int totalPage;
    //上一页
    private int prevPage;
    //下一页
    private int nextPage;

    /**
     * Instantiates a new Page result.
     *
     * @param currentPage the current page
     * @param pageSize    the page size
     * @param totalCount  the total count
     * @param data        the data
     */
    public PageResult(int currentPage, int pageSize, int totalCount, List<T> data) {
        this.currentPage = currentPage;
        this.pageSize = pageSize;
        this.totalCount = totalCount;
        this.data = data;

        //计算
        if (this.totalCount % this.pageSize == 0) {
            this.totalPage = this.totalCount / this.pageSize;
        } else {
            this.totalPage = this.totalCount / this.pageSize + 1;
        }

        if(this.currentPage - 1 >= 1) {
            this.prevPage = this.currentPage - 1;
        } else {
            this.prevPage = 1;
        }

        if(this.currentPage + 1 <= this.totalPage) {
            this.nextPage = this.currentPage + 1;
        } else {
            this.nextPage = this.totalPage;
        }
    }

    /**
     * Sets current page.
     *
     * @param currentPage the current page
     */
    public void setCurrentPage(int currentPage) {
        this.currentPage = currentPage;
    }

    /**
     * Sets page size.
     *
     * @param pageSize the page size
     */
    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    /**
     * Sets total count.
     *
     * @param totalCount the total count
     */
    public void setTotalCount(int totalCount) {
        this.totalCount = totalCount;
    }

    /**
     * Sets data.
     *
     * @param data the data
     */
    public void setData(List<T> data) {
        this.data = data;
    }

    /**
     * Sets total page.
     *
     * @param totalPage the total page
     */
    public void setTotalPage(int totalPage) {
        this.totalPage = totalPage;
    }

    /**
     * Sets prev page.
     *
     * @param prevPage the prev page
     */
    public void setPrevPage(int prevPage) {
        this.prevPage = prevPage;
    }

    /**
     * Sets next page.
     *
     * @param nextPage the next page
     */
    public void setNextPage(int nextPage) {
        this.nextPage = nextPage;
    }

    /**
     * Gets current page.
     *
     * @return the current page
     */
    public int getCurrentPage() {
        return currentPage;
    }

    /**
     * Gets page size.
     *
     * @return the page size
     */
    public int getPageSize() {
        return pageSize;
    }

    /**
     * Gets total count.
     *
     * @return the total count
     */
    public int getTotalCount() {
        return totalCount;
    }

    /**
     * Gets data.
     *
     * @return the data
     */
    public List<T> getData() {
        return data;
    }

    /**
     * Gets total page.
     *
     * @return the total page
     */
    public int getTotalPage() {
        return totalPage;
    }

    /**
     * Gets prev page.
     *
     * @return the prev page
     */
    public int getPrevPage() {
        return prevPage;
    }

    /**
     * Gets next page.
     *
     * @return the next page
     */
    public int getNextPage() {
        return nextPage;
    }
}
